package com.east.service.sale.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.east.bean.Company;
import com.east.dao.CompanyMapper;
import com.east.service.sale.CompanyService;
import com.east.utils.Pagenation;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
@Service("companyService")
public class CompanyServiceImpl implements CompanyService{
		@Autowired
		CompanyMapper companyMapper;

		@Override
		public Page<Company> findByPage(Pagenation pagenation, String key,String ztype) {
			Page<Company> startPage = PageHelper.startPage(pagenation.getPageNum(), pagenation.getPageSize());
			companyMapper.findAll(key, ztype);
			return startPage;
		}

		@Override
		public Company findByOne(Company company) {
			return companyMapper.selectByPrimaryKey(company.getcId());
		}

		@Override
		public boolean saveCompany(Company company) {
			Company cp = new Company();
			cp.setcAddress(company.getcAddress());//单位地址
			cp.setcBank(company.getcBank());//开户行名称
			cp.setcBankAmount(company.getcBankAmount());//银行账户
			cp.setcFax(company.getcFax());//公司传真
			cp.setcName(company.getcName());//公司名称
			cp.setcProduct(company.getcProduct());//主要产品
			cp.setcScope(company.getcScope());//经营范围[字段只对采购客户有效]
			cp.setcType(company.getcType());//公司类型
			cp.setcZtype(company.getcZtype());//公司类型 [1销售客户与2采购客户]
			cp.setcUuid(UUID.randomUUID().toString());
			int insert = companyMapper.insert(cp);
			if(insert>0) {
				return true;
			}
			return false;
		}

		@Override
		public boolean updateCompany(Company company) {
			Company cp = companyMapper.selectByPrimaryKey(company.getcId());
			cp.setcAddress(company.getcAddress());//单位地址
			cp.setcBank(company.getcBank());//开户行名称
			cp.setcBankAmount(company.getcBankAmount());//银行账户
			cp.setcFax(company.getcFax());//公司传真
			cp.setcName(company.getcName());//公司名称
			cp.setcProduct(company.getcProduct());//主要产品
			cp.setcScope(company.getcScope());//经营范围[字段只对采购客户有效]
			cp.setcType(company.getcType());//公司类型
			cp.setcZtype(company.getcZtype());//公司类型 [1销售客户与2采购客户]
			int insert = companyMapper.updateByPrimaryKey(cp);
			if(insert>0) {
				return true;
			}
			return false;
		}

		@Override
		public boolean delCompany(Company company) {
			int deleteByPrimaryKey = companyMapper.deleteByPrimaryKey(company.getcId());
			if(deleteByPrimaryKey>0) {
				return true;
			}
			return false;
		}
}
